var checkusername = 0;
var checkrealname = 0;
var checkphonenumber = 0;
var checkpassowrd = 0;
var checkrepassowrd = 0;
function check(username,realname,phonenumber,password,repassword,button){
	button.disabled=true;
	if(checkusername==0){
		checkUsername(username);
		button.disabled=false;
		return false;
	}
	if(checkrealname==0){
		checkRealname(realname);
		button.disabled=false;
		return false;
	}
	if(checkphonenumber==0){
		checkPhonenumber(phonenumber);
		button.disabled=false;
		return false;
	}
	if(checkpassowrd==0){
		checkPassowrd(password);
		button.disabled=false;
		return false;
	}
	if(checkrepassowrd==0){
		checkRePassowrd(repassword);
		button.disabled=false;
		return false;
	}
	button.form.submit();
}
function checkUsername(username){
	if(username==""){
		printResult("username_warn_txt","<label><b>*</b>用户不可以为空</label>","username_warn","error.png","warn_txt_error");
		checkusername = 0;
		return false;
	}
	if(!checknumber(username)){
		printResult("username_warn_txt","<label><b>*</b>用户名不可以全部为数字或邮箱</label>","username_warn","error.png","warn_txt_error");
		checkusername = 0;
		return false;
	}
	if(!checkmail(username)){
		printResult("username_warn_txt","<label><b>*</b>用户名不可以为邮箱</label>","username_warn","error.png","warn_txt_error");
		checkusername = 0;
		return false;
	}
	userService.checkUsername(username,function(data) {
		if("ok"==data){
			checkusername = 1;
			printResult("username_warn_txt","<label><b>*</b>用户名可以使用","username_warn","right.png","warn_txt_right");
		}else{
			checkusername = 0;
			printResult("username_warn_txt",data,"username_warn","error.png","warn_txt_error");
		}
	});
	
	return false;
}
function checkRealname(realname){
	if(realname==""){
		checkrealname = 0;
		printResult("realname_warn_txt","<label><b>*</b>真实姓名不可以为空</label>","realname_warn","error.png","warn_txt_error");
		return false;
	}else{
	    checkrealname = 1;
		printResult("realname_warn_txt","","realname_warn","right.png","warn_txt_right");
		return true;
	}
}

function checkPhonenumber(phonenumber){
	if(phonenumber==""){
		checkphonenumber = 0;
		printResult("phonenumber_warn_txt","<label><b>*</b>手机号码不可以为空</label>","phonenumber_warn","error.png","warn_txt_error");
		return false;
	}
	var myreg = /^(1+\d{10})$/;
	if(!myreg.test(phonenumber)||phonenumber.length!=11){
		checkphonenumber = 0;
		printResult("phonenumber_warn_txt","<label><b>*</b>手机号码填写不正确</label>","phonenumber_warn","error.png","warn_txt_error");
		return false;
	}else{
	    checkphonenumber = 1;
		printResult("phonenumber_warn_txt","","phonenumber_warn","right.png","warn_txt_right");
		return true;
	}
}
var password=0; 
function checkPassword(passworda){
	password=passworda;
	if(password==""){
		checkpassowrd = 0;
		printResult("password_warn_txt","<label><b>*</b>密码不可以为空</label>","password_warn","error.png","warn_txt_error");
		return false;
	}
	if(password.length < 6){
		checkpassowrd = 0;
		printResult("password_warn_txt","<label><b>*</b>密码必须大于等于6位</label>","password_warn","error.png","warn_txt_error");
		return false;
	}else{
		checkpassowrd = 1;
		printResult("password_warn_txt","","password_warn","right.png","warn_txt_right");
		return true;
	}
}
function checkRePassword(repassword){
	if(repassword !=password || password==""){
		checkrepassowrd = 0;
		printResult("repassword_warn_txt","<label><b>*</b>两次密码输入不一致</label>","repassword_warn","error.png","warn_txt_error");
		return false;
	}else{
		checkrepassowrd = 1;
		printResult("repassword_warn_txt","","repassword_warn","right.png","warn_txt_right");
		return true;
	}
	
}
function printResult(div,message,divwar,img,styleclass){
	//alert(div +"====>mess:"+message+"===>img:"+img);
	document.getElementById(div).innerHTML=message;
	document.getElementById(divwar).innerHTML="<img src=images/assets/"+img+">";
}
//function printResult(div,message){
	//document.getElementById(div).innerHTML="<label><b>*</b>"+message+"</label>";
	//alert("printResult=="+message);
//}
function printPhoto(div,photo){
	document.getElementById(div).innerHTML=photo;
	//alert("printPhoto===="+photo);
}

function checknumber(string) 
{ 
	var Letters = "1234567890"; 
	var i; 
	var c; 
	
	for( i = 0; i < string.length; i ++ ){ 
		c = string.charAt( i ); 
		if (Letters.indexOf(c) ==-1){ 
			 return true;
		} 
	} 
	return false; 
} 
function checkmail(string){
	var a='@';
	return (string.indexOf(a) == -1);
}
  
		function zhuche(){
		 jQuery.blockUI({ message:"<div id='dialog-reg' style='cursor:auto;position:absolute; top:0;_top:-267px; left:0;'>"
		+"<div class='hd'><h3>注册新用户</h3></div>"
		+"<div class='bd'><form id='register_form' action='/register.shtml' method='post' name='register_form'  onSubmit='return false;'>"
		+"<div id='username_warn_txt' style='margin:0px; padding:0px;position: relative; padding-left:70px;text-align:left;font-size:11px;'></div>"
		+"<div class='field'><label><b>*</b>用户名</label><input onblur='checkUsername(this.value);' id='username' name='account.username' type='text' /><div id='username_warn' style='margin:0px; text-align:left; '></div></div>"
		+"<div id='password_warn_txt' style='margin:0px; padding:0px;position: relative; padding-left:70px;text-align:left;font-size:11px;'></div>"
		+"<div class='field'><label><b>*</b>密码</label><input  onblur='checkPassword(this.value);' type='password' id='password' name='account.password' /><div id='password_warn' style='margin:0px; text-align:left; '></div></div>"
		+"<div id='repassword_warn_txt' style='margin:0px; padding:0px;position: relative; padding-left:70px;text-align:left;font-size:11px;'></div>"
		+"<div class='field'><label><b>*</b>确认密码</label><input  onblur='checkRePassword(this.value);' type='password' id='repassword'  name='repassword'/><div id='repassword_warn' style='margin:0px; text-align:left; '></div></div>"
		+"<div id='realname_warn_txt' style='margin:0px; padding:0px;position: relative; padding-left:70px;text-align:left;font-size:11px;'></div>"
		+"<div class='field'><label><b>*</b>真实姓名</label> <input  onblur='checkRealname(this.value)' type='text' id='realname' name='realName' /><div id='realname_warn'  style='margin:0px; text-align:left; '></div></div>"
		+"<div id='phonenumber_warn_txt' style='margin:0px; padding:0px;position: relative; padding-left:70px;text-align:left;font-size:11px;'></div>"
		+"<div class='field'><label><b>*</b>手机号</label><input  onblur='checkPhonenumber(this.value);' type='text' id='phonenumber' name='phonenumber' /><div id='phonenumber_warn' style='margin:0px; text-align:left; '></div></div>"	
		+"<div class='act'><button onClick='check(register_form.username.value,register_form.realName.value,register_form.phonenumber.value,register_form.password.value,register_form.repassword.value,this);return false;'></button></div></form>"
		+"</div><p class='close'><a href='' onClick='jQuery.unblockUI(50);return false;' title='关闭'>关闭</a></p>"
		+"</div>", css: { border: "0px solid #a00",left : "25%",top : "10%"} });
		}
		
/*		<p class='agree'><input type='checkbox'  style='width:15px; height:15px;' checked /> 我已经阅读并同意<a href=''>&lt;HOZOM服务条款&gt;</a></p>*/
		